'use strict';
const moment = require('moment');
module.exports = app => {
  const { INTEGER, STRING, DATE } = app.Sequelize;
  const flowSheet = app.model.define('flowsheet', {
    id: {
      type: INTEGER,
      primaryKey: true,
      autoIncrement: true,
    },
    money: {
      type: INTEGER,
    },
    contract_id: {
      type: INTEGER,
    },
    card: {
      type: STRING,
    },
    payer: {
      type: STRING,
    },
    payment: {
      type: STRING,
    },
    created_at: {
      type: DATE,
      get() {
        return moment(this.getDataValue('created_at')).format(
          'YYYY-MM-DD HH:mm:ss'
        );
      },
    },
    updated_at: {
      type: DATE,
      get() {
        return moment(this.getDataValue('updated_at')).format(
          'YYYY-MM-DD HH:mm:ss'
        );
      },
    },
  });

  flowSheet.associate = () => {
    flowSheet.belongsTo(app.model.Contract.Contract, {
      foreignKey: 'contract_id',
    });
  };
  return flowSheet;
};
